import Vue from 'vue'
import Vuex from 'vuex'
// import { filterObject } from '@/util/util'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    token: '',
    // openId 标识
    openId: '',
    userInfo: {
      //
    },
    activeAddress: {},
    // 对比模式
    isComparing: false,
    // 对比用报告id
    compareReportId: ''
  },
  getters: {
    // someGetter: (state) => {
    //   return ''
    // },
    // 用户是否登录
    isLogin: (state) => {
      return !!state.token
    }
  },
  actions: {
    // async getSomething({ commit, state }) {
    //   try {
    //     commit('SET_VALUE', {})
    //   } catch (error) {
    //     console.log(error)
    //   }
    // }
  },
  mutations: {
    SET_POSITION(state, position) {
      state.activeAddress = position
    },
    // 默认置空authCode
    UPDATE_WXLOGINIFNO(state, { token, openId }) {
      if (token) uni.setStorageSync('APP_TOKEN', token || null)
      state.token = token
      if (openId) state.openId = openId
    },
    SET_LOGOUTRESET(state) {
      state.token = ''
      state.openId = ''
    },
    SET_VALUE(state, { key, val }) {
      state[key] = val
    }
  }
})

export default store
